package com.xmut.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.util.SysUserUtils;
import com.xmut.entity.Repair;
import com.xmut.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *
 */
@Controller
@RequestMapping("/pass/repair")
public class FrontRepairController extends JsonBaseController{

    @Autowired
    private RepairService repairService;

    @Override
    protected String getView(String s) {
        return null;
    }

    @RequestMapping
    public String repair(Model model) {
        List<Repair> repairs = repairService.queryByUserId(SysUserUtils.getUserId());
        model.addAttribute("repairs",repairs);
        return "front/repair";
    }


    @ResponseBody
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Message create(@ModelAttribute Repair repair) {
        repair.setUserId(SysUserUtils.getUserId());
        repair.setReplyState("报修中");
        repairService.save(repair);
        return coverMessage("200");
    }


}
